package com.itcoon.transform.assemble.handler.parameterized;

import com.itcoon.transform.assemble.handler.AssembleHandlerComposite;
import com.itcoon.transform.base.definition.InjectDefinition;
import org.springframework.beans.factory.annotation.Autowired;

import java.lang.reflect.ParameterizedType;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public class StandardTargetParameterizedTypeHandler implements AssembleForTargetParameterizedTypeHandler {

    @Autowired
    private AssembleHandlerComposite composite;

    @Override
    public boolean support(ParameterizedType targetPropertyType, Object originGetterValue, List<InjectDefinition.InjectInfo> injectInfos) {
        Class<?> rawType = (Class<?>)targetPropertyType.getRawType();
        return !Collection.class.isAssignableFrom(rawType) && !Map.class.isAssignableFrom(rawType);
    }

    @Override
    public Object handle(ParameterizedType targetPropertyType, Object originGetterValue, List<InjectDefinition.InjectInfo> injectInfos) {
        return composite.handle(targetPropertyType, originGetterValue, injectInfos);
    }
}
